/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import BancoDeDados.GerenciarOperacoesMySQL;
import javax.swing.JOptionPane;

/**
 *
 * @author Igor Bastos
 */
public class FrameCriacaoBD extends javax.swing.JFrame {

    /**
     * Creates new form FrameInstalacaoBD
     */
    public FrameCriacaoBD() {
        this.setResizable(false);
        initComponents();

        //Centraliza o FrameJogo
        this.setLocationRelativeTo(null);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonIniciarCriacaoBD = new javax.swing.JButton();
        scrollPanelAvisoImportante = new javax.swing.JScrollPane();
        jTextPane1 = new javax.swing.JTextPane();
        labelStatus = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Criar Banco de Dados");

        buttonIniciarCriacaoBD.setText("Iniciar Criação do BD");
        buttonIniciarCriacaoBD.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonIniciarCriacaoBDActionPerformed(evt);
            }
        });

        jTextPane1.setEditable(false);
        jTextPane1.setText("Este software tem como objetivo a criação do arquivo de Banco \nde Dados para o projeto TREF, sendo assim, irá recriar as tabelas\ne procedimentos que serão utilizados para armazenamento e \nprocessamento dos dados.\nImportante observar que este procedimento irá sobrescrever\nqualquer banco de dados do projeto TREF, anteriormente criado.\nSó inicie o procedimento caso seja realmente necessário.");
        scrollPanelAvisoImportante.setViewportView(jTextPane1);

        labelStatus.setText("Status:");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(scrollPanelAvisoImportante, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(114, 114, 114)
                        .addComponent(buttonIniciarCriacaoBD))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(labelStatus)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(scrollPanelAvisoImportante, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(buttonIniciarCriacaoBD)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(labelStatus)
                .addContainerGap(21, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void buttonIniciarCriacaoBDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonIniciarCriacaoBDActionPerformed
        // TODO add your handling code here:
        GerenciarOperacoesMySQL gen = new GerenciarOperacoesMySQL();
        int reply = JOptionPane.showConfirmDialog(null, "Este procedimento sobrescreverá qualquer instância do\n"
                + "Banco de Dados do projeto TREF, anteriormente criada.\n"
                + "\n"
                + "Deseja realmente continuar?", "Atenção!", JOptionPane.YES_NO_OPTION);
        if (reply == JOptionPane.YES_OPTION) {
            labelStatus.setText("Status: executando processo");
            JOptionPane.showMessageDialog(null, "Aguarte até que o Status avise o término do processamento.", "Atenção!", JOptionPane.INFORMATION_MESSAGE);
            gen.createTables();
            gen.createRoutines();
            labelStatus.setText("Status: Fim do processo");
        }
    }//GEN-LAST:event_buttonIniciarCriacaoBDActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FrameCriacaoBD.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FrameCriacaoBD.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FrameCriacaoBD.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FrameCriacaoBD.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new FrameCriacaoBD().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buttonIniciarCriacaoBD;
    private javax.swing.JTextPane jTextPane1;
    private javax.swing.JLabel labelStatus;
    private javax.swing.JScrollPane scrollPanelAvisoImportante;
    // End of variables declaration//GEN-END:variables

}
